package cn.itcast.test;

import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.dao.base.StandardDao;
import cn.itcast.bos.domain.base.Standard;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:applicationContext.xml")
public class Crud {

	//注入dao层对象
	@Autowired
	private StandardDao standardDao;
	
	/**根据命名规则自动进行操作
	 * find,query+By+列名，根据哪一列的值来查询订单
	 */
	//查询快递名称为“省内快递”的收派标准
	@Test
	public void  test1(){
		
	//List<Standard> list	=standardDao.findByName("省内快递");
		List<Standard> list = standardDao.queryStandardUseName("省内快递");
	for(Standard  s:list){
		
		System.out.println(s);
	}
		
	}
	
	//查询快递id为1的收派标准
	@Test
	public void test2(){
		//jspRespository底层自带的删除方法
		Standard s=standardDao.findById(1);
		
		System.out.println(s);
	}
	
	
	//删除方法
	@Test
	//添加事务控制
	@Transactional
    @Rollback(false)
	public void test3(){
		try{
//			standardDao.delete(4);
			standardDao.dalateByName("海南省");
		} catch(Exception e) {
			System.out.println(e.getMessage());
		}
	}
	
	
   //修改数据	
   @Test
   @Transactional
   @Rollback(false)
   public void  test4(){
	   
	   standardDao.update(5,"省外快递") ;
	   
   }
	
}
